home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17502 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  71 lines

  1. Path: news.infi.net!usenet
  2. From: Scott Hightower <hightowr@lex.infi.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: int::~int()
  5. Date: Tue, 16 Apr 1996 00:47:19 -0400
  6. Organization: InfiNet
  7. Message-ID: <31732657.5795@lex.infi.net>
  8. References: <317083F7.116E@public.sta.net.cn> <marnoldDpuDu9.D7s@netcom.com>
  9. NNTP-Posting-Host: h-admission.lex.infi.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01Gold (Win95; I)
  14.  
  15. Matt Arnold wrote:
  16. > Xu Yifeng <jafd@public.sta.net.cn> writes:
  17. > >Hi everybody,
  18. > >can your compiler compile following program?
  19. > >//------------------------
  20. > >void main()
  21. > >{
  22. > >     int i = 0;
  23. > >     i.int::~int();
  24. > >}
  25. > >//------------------------
  26. > >is it a legal C++ program?
  27. > It's supposed to be, but most C++ compiler's will not compile it.
  28. > In fact, this exact sitution is encountered in the Standard Template
  29. > Library (STL), which contains the following template function...
  30. > template <class T>
  31. > inline void destroy(T* pointer) {
  32. >     pointer->~T();
  33. > }
  34. > ...which is supposed to be used to destroy anything, including an
  35. > instance of an int, just like your sample code wants to.
  36. > To make STL work with current compilers, you'll find it also contains
  37. > work-around versions of destroy().  There's one specifically for int,
  38. > and it looks like this...
  39. > inline void destroy(int*) {}
  40. > ...which is what the template version is supposed to do; nothing.  STL
  41. > contains about 50 or so of these specific versions of destroy() (for
  42. > ints, chars, floats, etc.).
  43. > You sample code is legal as far as the language goes, but probably
  44. > not as far as your compiler is concerned.  Mine, Borland C++ 4.52,
  45. > will not compile it either.  However, I think Borland C++ 5.0 will.
  46. > Regards,
  47. > -------------------------------------------------------------------------
  48. > Matt Arnold                       |        | ||| | |||| |  | | || ||
  49. > marnold@netcom.com                |        | ||| | |||| |  | | || ||
  50. > Boston, MA                        |      0 | ||| | |||| |  | | || ||
  51. > 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  52. > C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  53. > -------------------------------------------------------------------------
  54. BC++ 5.0 did not like it, either.
  55.  
  56.